﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using ZLDC.Topo.Model.Estate;

namespace ZLDC.Estate.CM
{
    public partial class CustomerCheckList : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string station = this.info.m_sStation;

                if ((_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station)) || ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源"))
                {
                    divCheck.Visible = true;
                    hStation.Value = station;
                }
                hUserid.Value = this.info.m_sUserID;

            }
        }

        /// <summary>
        /// 转到私客(指定接客人)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btToPty_Click(object sender, System.EventArgs e)
        {
            int id = _Convert.ToInt(hID.Value, 0);

            if (id <= 0)
            {
                _JavaScript.Alert(this.Page, "请先选择您要操作的客源");
                return;
            }

            string userNoAndName = tbMakeUser.Text;      // 工号及名称

            if (userNoAndName.Trim().Equals(""))
            {
                _JavaScript.Alert(this.Page, "接客人不能为空");
                return;
            }

            string userName = string.Empty; // 姓名
            string userNo = string.Empty;   // 工号
            int userId = 0;                 // 楼盘系统用户ID
            _Utility.GetUserNoAndUserName(userNoAndName.Trim(), out userName, out userNo);
            userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserName(userName,userNo);

            // 更新接客人及接客人部门信息
            UserInfo info = ZLDC.Topo.BLL.Estate.UserBLL.GetUserInfoByUserID(userId);

            if (info == null || info.Id <= 0)
            {
                _JavaScript.Alert(this.Page, "您选择接客人不存在，请确认是否已离职");
                return;
            }

            int deptid = info.Dept_id;
            string deptname = info.DeptName;
            int userid = info.Id;
            string username = info.Name;

            string outmsg = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.UpdateCustomerCheckList(0, 2, id, userid, username, deptid, deptname);
            if (outmsg == "审批通过")
            {
                ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(0, id, deptid, deptname, userid, username, "转客审核", outmsg, 0, 0);

                // 计入量化
                ZLDC.Topo.Model.Estate.CustomerInfo customer = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_detail(id);
                ZLDC.Topo.BLL.Estate.quantificationBLL.UpdateCustomerQuantification(id, customer.Tradetype, customer.OwnerDeptId, customer.OwnerDept, customer.Ownerid, customer.Owner);
            }

        }

    }
}
